package org.rency.crawler.app.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.rency.crawler.fetch.repository.FetchPageRepository;
import org.rency.crawler.fetch.repository.FetchedQueueRepository;
import org.rency.crawler.fetch.repository.HostQueueRepository;
import org.rency.crawler.fetch.repository.MetaResourceRepository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/24 16:11<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/24 16:11
 */
@RestController
@Api(value = "refresh", description = "缓存刷新")
public class RefreshController {

  @Resource
  private FetchPageRepository           fetchPageRepository;

  @Resource
  private FetchedQueueRepository        fetchedQueueRepository;

  @Resource
  private HostQueueRepository           hostQueueRepository;

  @Resource
  private MetaResourceRepository        metaResourceRepository;

  @RequestMapping(value = "/meta", method = RequestMethod.GET)
  @ApiOperation(value="刷新配置", notes = "刷新配置")
  public String refreshMeta() {
    metaResourceRepository.refreshAll();
    return "Ok!";
  }

  @RequestMapping(value = "/fetch/page/remove", method = RequestMethod.GET)
  @ApiOperation(value="清空已抓取文档", notes = "清空已抓取文档")
  public String removeFetchPage() {
    long count = fetchPageRepository.removeAll();
    return "移除:"+count;
  }

  @RequestMapping(value = "/queue/fetched/remove", method = RequestMethod.GET)
  @ApiOperation(value="清空已抓取队列", notes = "清空已抓取URL队列")
  public String removeFetched() {
    int count = fetchedQueueRepository.deleteAll();
    return "移除:"+count;
  }

  @RequestMapping(value = "/queue/host/remove", method = RequestMethod.GET)
  @ApiOperation(value="清空域名队列", notes = "清空域名队列")
  public String removeHost() {
    long count = hostQueueRepository.removeAll();
    return "移除:"+count;
  }

}
